/**
 * 函数防抖
 */
/**
 * @param {Function} func 事件响应函数
 * @param {Number} delay 延迟时间
 * @param {Boolean} imme 是否立即执行
 */
export function debounce(func, delay, imme = true) {
	let timer

	return function() {
		const _self = this,
			args = arguments

		let res

		if (timer) clearTimeout(timer)

		if (imme) {
			const callNow = !timer

			timer = setTimeout(() => {
				timer = null
			}, delay)

			if (callNow) res = func.apply(_self, args)
		} else {
			timer = setTimeout(() => {
				res = func.apply(_self, args)
			}, delay)
		}

		return res
	}
}
